﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Portal.UserControl
{
    public partial class Header : System.Web.UI.UserControl
    {
        private int categoryId;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;

            if (Request.Params.AllKeys.Contains("Kw"))
            {
                txtKeyword.Text = Request["Kw"];
            }
            int.TryParse(Request["CategoryId"], out categoryId);
            hidSearchType.Value = categoryId.ToString();

            InitSearchType();
        }

        private void InitSearchType()
        {
            var sb = new StringBuilder();
            sb.AppendFormat("<li{0}><a category=\"0\">所有</a></li>", categoryId == 0 ? " class=\"selected\"" : "");
            sb.AppendFormat("<li{0}><a category=\"1\">猎头</a></li>", categoryId == 1 ? " class=\"selected\"" : "");
            sb.AppendFormat("<li{0}><a category=\"2\">医院</a></li>", categoryId == 2 ? " class=\"selected\"" : "");
            sb.AppendFormat("<li{0}><a category=\"3\">大学</a></li>", categoryId == 3 ? " class=\"selected\"" : "");
            sb.AppendFormat("<li{0}><a category=\"4\">IT公司</a></li>", categoryId == 4 ? " class=\"selected\"" : "");
            litSearchType.Text = sb.ToString();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            int categoryId = int.Parse(hidSearchType.Value);
            string keyword = txtKeyword.Text.Trim();
            Response.Redirect(string.Format("/SearchResult.aspx?CategoryId={0}&Kw={1}&PageSize=10&PageNum=1", categoryId, keyword));
        }
    }
}